﻿using System;
using System.Windows;
using System.Windows.Data;

namespace DIS.WindowsPhone.Toolkit.Controls.Extensions
{
    internal static class Extensions
    {
        private const string ExternalAddress = "app://external/";

        public static void RegisterNotification(this FrameworkElement element, string propertyName, PropertyChangedCallback callback)
        {
            DependencyProperty prop = DependencyProperty.RegisterAttached("Notification" + propertyName,
                                                                          typeof(object),
                                                                          typeof(FrameworkElement),
                                                                          new PropertyMetadata(callback));

            element.SetBinding(prop, new Binding(propertyName) { Source = element });
        }

        /// <summary>
        /// Returns whether the uri is from an external source.
        /// </summary>
        /// <param name="uri">The uri</param>
        public static bool IsExternalNavigation(this Uri uri)
        {
            return (ExternalAddress == uri.ToString());
        }
    }
}
